import java.util.*;
// 牛客网 空调遥控
public class Main {
    // 修正：将Main改为main
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        char[] c = s.toCharArray();
        int ans = Integer.MAX_VALUE;  // 这里可能应该用Integer.MIN_VALUE寻找最大值？
        if(c.length == 1 || c.length == 0) {
            System.out.print(-1);
            return;
        }
        if(c.length == 2) {
            if(c[0] == c[1]) {
                System.out.print(2);
                return;
            }
        }
        for(int i = 1; i < c.length - 1; i++) {
            if(c[i-1] == c[i+1]) {
                ans = 3;
            }
            if(c[i] == c[i+1]) {
                ans = 2;
                break;
            }
            if(c[i] == c[i-1]) {
                ans = 2;
                break;
            }
        }
        ans = (ans == Integer.MAX_VALUE) ? -1 : ans;
        System.out.print(ans);
    }

    public static int DealLength(int left, int right, char[] c) {
        int res = 0;
        if(right - left == 2) {
            res = 3;
        }else {
            res = 2;  // 修正：相邻两个相同字符组成的回文长度应该是2
        }
        left--;
        right++;
        while(left >= 0 && right <= c.length-1) {
            if(c[left] == c[right]) {
                res += 2;
                left--;
                right++;
            }else {
                break;
            }
        }
        return res;
    }


// 牛客网 小红的ABC
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        char[] c = s.toCharArray();
        int ans = Integer.MAX_VALUE;  // 这里可能应该用Integer.MIN_VALUE寻找最大值？
        if(c.length == 1 || c.length == 0) {
            System.out.print(-1);
            return;
        }
        if(c.length == 2) {
            if(c[0] == c[1]) {
                System.out.print(2);
                return;
            }
        }
        for(int i = 1; i < c.length - 1; i++) {
            if(c[i-1] == c[i+1]) {
                ans = 3;
            }
            if(c[i] == c[i+1]) {
                ans = 2;
                break;
            }
            if(c[i] == c[i-1]) {
                ans = 2;
                break;
            }
        }
        ans = (ans == Integer.MAX_VALUE) ? -1 : ans;
        System.out.print(ans);
    }


// 牛客网 DP23 不相邻取数
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        int[] dp = new int[n+1];
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            if(i == 0) {
                dp[i+1] = arr[i];
            }else if(i == 1) {
                dp[i+1] = Math.max(arr[i-1], arr[i]);
            }else {
                dp[i+1] = Math.max(dp[i], dp[i-1] + arr[i]);
            }
        }
        System.out.print(dp[n]);
    }
}